Provide overloaded helpers to gbfile to make it more forgiving of QString arguments.
authorrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 9 Feb 2013 06:00:22 +0000 (06:00 +0000)
committerrobertlipe <robertlipe@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Sat, 9 Feb 2013 06:00:22 +0000 (06:00 +0000)
Minor warning cleanups.

gpsbabel/garmin_txt.cc
gpsbabel/gbfile.cc
gpsbabel/gbfile.h
gpsbabel/geo.cc
gpsbabel/pathaway.cc

index 23093a8858f7fd2b6f9ba0565795049dbac3a8d8..9c8ad1edc114c895f9f7657c48d0eeba6ebf9913 100644 (file)
@@ -56,7 +56,7 @@ static waypoint** wpt_a;
 static int wpt_a_ct;
 static grid_type grid_index;
 static int datum_index;
-static char* datum_str;
+static const char* datum_str;
 static int current_line;
 static char* date_time_format = NULL;
 static int precision = 3;
@@ -152,17 +152,18 @@ static const char* headers[] = {
 
 /* helpers */
 
-static char*
-get_option_val(char* option, char* def)
+static const char*
+get_option_val(const char* option, const char* def)
 {
-  char* c = (option != NULL) ? option : def;
+  const char* c = (option != NULL) ? option : def;
   return c;
 }
 
 static void
 init_date_and_time_format(void)
 {
-  char* f, *c;
+  const char* f;
+  const char* c;
 
   f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT);
   date_time_format = convert_human_date_format(f);
@@ -172,7 +173,7 @@ init_date_and_time_format(void)
   f = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT);
   c = convert_human_time_format(f);
   date_time_format = xstrappend(date_time_format, c);
-  xfree(c);
+  xfree((void*) c);
 }
 
 static void
@@ -468,7 +469,7 @@ print_speed(double* distance, time_t* time)
 {
   int idist;
   double dist = *distance;
-  char* unit;
+  const char* unit;
 
   if (!gtxt_flags.metric) {
     dist = METERS_TO_MILES(dist) * 1000.0;
@@ -554,7 +555,7 @@ write_waypt(const waypoint* wpt)
 
   gbfprintf(fout, "Waypoint\t%s\t", (wpt->shortname) ? wpt->shortname : "");
   if (wpt_class <= gt_waypt_class_airport_ndb) {
-    char* temp = wpt->notes;
+    const char* temp = wpt->notes;
     if (temp == NULL) {
       if (wpt->description && (strcmp(wpt->description, wpt->shortname) != 0)) {
         temp = wpt->description;
@@ -750,7 +751,7 @@ track_disp_wpt_cb(const waypoint* wpt)
 static void
 garmin_txt_wr_init(const char* fname)
 {
-  char* grid_str;
+  const char* grid_str;
 
   memset(&gtxt_flags, 0, sizeof(gtxt_flags));
 
index c541336409a4b791c7ce9fc2cb2e0dfed7353893..2cbd8edbb2bca9558e240353fc1bc47f0b42c648 100644 (file)
@@ -774,6 +774,16 @@ gbfputs(const char* s, gbfile* file)
   return gbfwrite(s, 1, strlen(s), file);
 }
 
+// This is a depressing hack, meant to ease the pain from C strings
+// to QStrings, which are consitently encoded.
+int
+gbfputs(const QString& s, gbfile* file)
+{
+  const char* qs = s.toUtf8().data();
+  unsigned int l = strlen(qs);
+  return gbfwrite(qs, 1, l, file);
+}
+
 /*
  * gbfwrite: (as fwrite)
  */
index 4bb73c45eff04a4772d3f7d9725b3741cc47188a..22575cfccb4fe647e639068dfbc0d06ad5bc6726 100644 (file)
@@ -26,6 +26,8 @@
 #include <ctype.h>
 #include <stdarg.h>
 #include <string.h>
+#include <QtCore/QString.h>
+
 #include "defs.h"
 #include "cet.h"
 
@@ -98,6 +100,7 @@ int gbvfprintf(gbfile* file, const char* format, va_list ap);
 int gbfprintf(gbfile* file, const char* format, ...);
 int gbfputc(int c, gbfile* file);
 int gbfputs(const char* s, gbfile* file);
+int gbfputs(const QString& s, gbfile* file);
 int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file);
 int gbfflush(gbfile* file);
 
index 7ce2bc61556892bff4f6d8321f8204737ab001ff..c30109f7065285b06c0af9abd43081581a5ecb49 100644 (file)
@@ -246,7 +246,7 @@ static void
 geo_wr_deinit(void)
 {
   writer.writeEndDocument();
-  gbfputs(ostring.toUtf8().data(),ofd);
+  gbfputs(ostring,ofd);
   gbfclose(ofd);
   ofd = NULL;
 }
index 2216e6790f8a4179a7b269709c84a9c2fceb9c45..8ded97995d668793f4644c1640175419ce9d04c9 100644 (file)
@@ -132,7 +132,7 @@ internal_debug2(const char *format, ...)
  */
 
 static
-char *ppdb_strcat(char *dest, const char *src, char *def, int *size)
+char *ppdb_strcat(char *dest, const char *src, const char *def, int *size)
 {
   int len;
   char *res;
@@ -212,7 +212,7 @@ char *str_pool_get(size_t size)
 }
 
 static
-char *str_pool_getcpy(const char *src, char *def)
+char *str_pool_getcpy(const char *src, const char *def)
 {
   char *res;